package vtt.android.lichphatsongbongda.adapters;

import java.util.List;

import vtt.android.library.VttBaseApplication;
import vtt.android.library.utils.VttLog;
import vtt.android.lichphatsongbongda.R;
import vtt.android.lichphatsongbongda.entities.TVScheduleItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;

public class TVScheduleAdapter extends ArrayAdapter<TVScheduleItem> {

	protected VttLog log = new VttLog("TVScheduleAdapter", VttBaseApplication.isDebuggable);
	protected Context mContext;
	protected List<TVScheduleItem> items;

	public TVScheduleAdapter(Context context, List<TVScheduleItem> items) {
		super(context, 0, items);
		this.mContext = context;
		this.items = items;
	}
	
	@Override
	public boolean isEnabled(int position) {
		// disable click
		return false;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		//log.d("VTT>>> getView position " + position);
		ViewHolder holder;
		if (view == null) {
			LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = layoutInflater.inflate(R.layout.row_tv_schedule, null);
			holder = new ViewHolder(view);
			view.setTag(holder);
		}
		holder = (ViewHolder) view.getTag();
		if (items != null) {
			final TVScheduleItem resultItem = items.get(position);
			if (resultItem.hasHeader()) {
				holder.header.setVisibility(View.VISIBLE);
				holder.header.setText(resultItem.getHeaderTime());
			} else {
				holder.header.setVisibility(View.GONE);
			}
			holder.tvTranDau.setText(resultItem.getTrandau().trim());
			holder.tvGiaiDau.setText(resultItem.getGiaidau().trim());
			holder.tvThoiGian.setText(resultItem.getThoigian().trim());
			holder.tvKenh.setText(resultItem.getKenh().trim());
		}

		return view;
	}

	class ViewHolder {
		@InjectView(R.id.tv_time_header)
		TextView header;
		@InjectView(R.id.row_content)
		View rowContent;
		
		@InjectView(R.id.tv_trandau)
		TextView tvTranDau;
		@InjectView(R.id.tv_giaidau)
		TextView tvGiaiDau;
		@InjectView(R.id.tv_thoigian)
		TextView tvThoiGian;
		@InjectView(R.id.tv_kenh)
		TextView tvKenh;

		public ViewHolder(View view) {
			ButterKnife.inject(this, view);
		}
	}

}
